(* Content-type: application/mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 7.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       145,          7]
NotebookDataLength[     10841,        286]
NotebookOptionsPosition[     10475,        269]
NotebookOutlinePosition[     10820,        284]
CellTagsIndexPosition[     10777,        281]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{"{", 
   RowBox[{
    RowBox[{"FileNameSetter", "[", 
     RowBox[{
      RowBox[{"Dynamic", "@", "FileName"}], ",", "\"\<Save\>\""}], "]"}], ",", 
    RowBox[{"Dynamic", "@", "FileName"}]}], "}"}], " ", "*)"}]], "Input",
 CellChangeTimes->{{3.4602886380186853`*^9, 3.4602886442999353`*^9}}],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"TN", " ", "=", " ", "10"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"S1", " ", "=", " ", 
   RowBox[{"RandomChoice", "[", 
    RowBox[{"AA", ",", " ", "TN"}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"S2", " ", "=", " ", 
   RowBox[{"RandomChoice", "[", 
    RowBox[{"AA", ",", " ", "TN"}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"SingleLetterRule", " ", "=", " ", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"ALA", "\[Rule]", "\"\<A\>\""}], ",", " ", 
      RowBox[{"ARG", "\[Rule]", "\"\<R\>\""}], ",", " ", 
      RowBox[{"ASN", "\[Rule]", "\"\<N\>\""}], ",", " ", 
      RowBox[{"ASP", "\[Rule]", "\"\<D\>\""}], ",", " ", 
      RowBox[{"CYS", "\[Rule]", "\"\<C\>\""}], ",", " ", 
      RowBox[{"GLN", "\[Rule]", "\"\<Q\>\""}], ",", " ", 
      RowBox[{"GLU", "\[Rule]", "\"\<E\>\""}], ",", " ", 
      RowBox[{"GLY", "\[Rule]", "\"\<G\>\""}], ",", " ", 
      RowBox[{"HIS", "\[Rule]", "\"\<H\>\""}], ",", " ", 
      RowBox[{"ILE", "\[Rule]", "\"\<I\>\""}], ",", " ", 
      RowBox[{"LEU", "\[Rule]", "\"\<L\>\""}], ",", " ", 
      RowBox[{"LYS", "\[Rule]", "\"\<K\>\""}], ",", " ", 
      RowBox[{"MET", "\[Rule]", "\"\<M\>\""}], ",", " ", 
      RowBox[{"PHE", "\[Rule]", "\"\<F\>\""}], ",", " ", 
      RowBox[{"PRO", "\[Rule]", "\"\<P\>\""}], ",", " ", 
      RowBox[{"SER", "\[Rule]", "\"\<S\>\""}], ",", " ", 
      RowBox[{"THR", "\[Rule]", "\"\<T\>\""}], ",", " ", 
      RowBox[{"TRP", "\[Rule]", "\"\<W\>\""}], ",", " ", 
      RowBox[{"TYR", "\[Rule]", "\"\<Y\>\""}], ",", " ", 
      RowBox[{"VAL", "\[Rule]", "\"\<V\>\""}], ",", " ", 
      RowBox[{"ASX", "\[Rule]", "\"\<B\>\""}], ",", " ", 
      RowBox[{"GLX", "\[Rule]", "\"\<Z\>\""}], ",", " ", 
      RowBox[{"XAA", "\[Rule]", "\"\<X\>\""}]}], "}"}]}], ";"}], 
  "\[IndentingNewLine]", 
  RowBox[{"(*", " ", 
   RowBox[{"SingleLetterRule", "[", 
    RowBox[{"[", 
     RowBox[{"All", ",", " ", "1"}], "]"}], "]"}], " ", 
   "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"AA", " ", "=", " ", 
   RowBox[{"{", 
    RowBox[{
    "ALA", ",", "ARG", ",", "ASN", ",", "ASP", ",", "CYS", ",", "GLN", ",", 
     "GLU", ",", "GLY", ",", "HIS", ",", "ILE", ",", "LEU", ",", "LYS", ",", 
     "MET", ",", "PHE", ",", "PRO", ",", "SER", ",", "THR", ",", "TRP", ",", 
     "TYR", ",", "VAL", ",", "ASX", ",", "GLX"}], "}"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"AlignSingle", " ", "=", " ", 
   RowBox[{"Characters", "[", 
    RowBox[{"SequenceAlignment", "[", 
     RowBox[{
      RowBox[{"StringJoin", "[", 
       RowBox[{"S1", " ", "/.", " ", "SingleLetterRule"}], "]"}], ",", " ", 
      RowBox[{"StringJoin", "[", 
       RowBox[{"S2", " ", "/.", " ", "SingleLetterRule"}], "]"}], ",", 
      RowBox[{"SimilarityRules", "\[Rule]", "\"\<BLOSUM62\>\""}]}], "]"}], 
    " ", "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"PadLists", "[", 
    RowBox[{"a_", ",", "b_"}], "]"}], " ", ":=", " ", 
   RowBox[{
    RowBox[{"With", "[", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{"l", " ", "=", " ", 
        RowBox[{"Max", "[", 
         RowBox[{
          RowBox[{"Length", "[", "a", "]"}], ",", " ", 
          RowBox[{"Length", "[", "b", "]"}]}], "]"}]}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"PadRight", "[", 
         RowBox[{"a", ",", " ", "l"}], "]"}], ",", " ", 
        RowBox[{"PadRight", "[", 
         RowBox[{"b", ",", " ", "l"}], "]"}]}], "}"}]}], "]"}], " ", "/.", 
    " ", 
    RowBox[{"0", "\[Rule]", "\"\<-\>\""}]}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"PaddedAlign", " ", "=", " ", 
   RowBox[{"Map", "[", 
    RowBox[{
     RowBox[{"Function", "[", 
      RowBox[{"u", ",", " ", 
       RowBox[{"If", "[", 
        RowBox[{
         RowBox[{
          RowBox[{"Depth", "[", "u", "]"}], ">", "2"}], ",", 
         RowBox[{"PadLists", "[", 
          RowBox[{
           RowBox[{"u", "[", 
            RowBox[{"[", "1", "]"}], "]"}], ",", 
           RowBox[{"u", "[", 
            RowBox[{"[", "2", "]"}], "]"}]}], "]"}], ",", " ", "u"}], "]"}]}],
       "]"}], ",", "AlignSingle"}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"$RecursionLimit", "=", "10000"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"WithGaps", "[", 
    RowBox[{"p_", ",", " ", "l_"}], "]"}], " ", ":=", " ", 
   RowBox[{"If", "[", 
    RowBox[{
     RowBox[{
      RowBox[{
       RowBox[{"Length", "[", "p", "]"}], "\[Equal]", "0"}], " ", "||", " ", 
      RowBox[{
       RowBox[{"Length", "[", "l", "]"}], " ", "\[Equal]", "0"}]}], ",", 
     RowBox[{"{", "}"}], " ", ",", "\[IndentingNewLine]", 
     RowBox[{"If", " ", "[", 
      RowBox[{
       RowBox[{
        RowBox[{"First", "[", "p", "]"}], " ", "\[Equal]", " ", "\"\<-\>\""}],
        ",", " ", 
       RowBox[{"Join", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{"{", "}"}], "}"}], ",", " ", 
         RowBox[{"WithGaps", "[", 
          RowBox[{
           RowBox[{"Rest", "[", "p", "]"}], ",", " ", "l"}], "]"}]}], "]"}], 
       ",", " ", "\[IndentingNewLine]", "\t\t\t\t     ", 
       RowBox[{"If", "[", 
        RowBox[{
         RowBox[{
          RowBox[{"(", 
           RowBox[{"\"\<seq\>\"", "/.", 
            RowBox[{"First", "[", "l", "]"}]}], ")"}], " ", "!=", " ", 
          RowBox[{"First", "[", "p", "]"}]}], ",", " ", 
         RowBox[{"Throw", "[", "sanity_fail", "]"}], ",", 
         "\[IndentingNewLine]", "\t\t\t\t\t", 
         RowBox[{"Join", "[", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"First", "[", "l", "]"}], "}"}], ",", 
           RowBox[{"WithGaps", "[", 
            RowBox[{
             RowBox[{"Rest", "[", "p", "]"}], ",", 
             RowBox[{"Rest", "[", "l", "]"}]}], "]"}]}], "]"}]}], "]"}]}], 
      "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"ForExport", "[", 
    RowBox[{"Name_", ",", " ", "S_"}], "]"}], ":=", " ", 
   RowBox[{
   "\"\<const \>\"", "~~", "Name", "~~", "\"\<:Array=\>\"", " ", "~~", " ", 
    RowBox[{"StringReplace", "[", 
     RowBox[{
      RowBox[{"(", 
       RowBox[{"ToString", "[", 
        RowBox[{"S", ",", "InputForm"}], "]"}], ")"}], ",", " ", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"\"\<{\>\"", "\[Rule]", "\"\<[\>\""}], ",", " ", 
        RowBox[{"\"\<}\>\"", "\[Rule]", "\"\<]\>\""}]}], "}"}]}], "]"}], 
    "~~", "\"\<;\>\"", "~~", "\"\<\\n\\n\>\""}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"EX", " ", "=", " ", 
   RowBox[{
    RowBox[{"ForExport", "[", 
     RowBox[{
      RowBox[{"\"\<TestSeqA\>\"", "~~", 
       RowBox[{"ToString", "@", "TN"}]}], ",", " ", 
      RowBox[{"S1", "/.", "SingleLetterRule"}]}], "]"}], "~~", 
    RowBox[{"ForExport", "[", 
     RowBox[{
      RowBox[{"\"\<TestSeqB\>\"", "~~", 
       RowBox[{"ToString", "@", "TN"}]}], ",", " ", 
      RowBox[{"S2", "/.", "SingleLetterRule"}]}], "]"}], " ", "~~", " ", 
    RowBox[{"ForExport", "[", 
     RowBox[{
      RowBox[{"\"\<TestResA\>\"", "~~", 
       RowBox[{"ToString", "@", "TN"}]}], ",", " ", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Map", "[", 
        RowBox[{
         RowBox[{"Function", "[", 
          RowBox[{"u", ",", " ", 
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"Depth", "[", "u", "]"}], ">", "2"}], ",", 
             RowBox[{"u", "[", 
              RowBox[{"[", "1", "]"}], "]"}], ",", "u"}], "]"}]}], "]"}], ",",
          "PaddedAlign"}], "]"}], "]"}]}], "]"}], " ", "~~", " ", 
    RowBox[{"ForExport", "[", 
     RowBox[{
      RowBox[{"\"\<TestResB\>\"", "~~", 
       RowBox[{"ToString", "@", "TN"}]}], ",", " ", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Map", "[", 
        RowBox[{
         RowBox[{"Function", "[", 
          RowBox[{"u", ",", " ", 
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"Depth", "[", "u", "]"}], ">", "2"}], ",", 
             RowBox[{"u", "[", 
              RowBox[{"[", "2", "]"}], "]"}], ",", "u"}], "]"}]}], "]"}], ",",
          "PaddedAlign"}], "]"}], "]"}]}], "]"}]}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{"Export", "[", 
  RowBox[{
   RowBox[{
   "\"\<C:\\\\Documents and \
Settings\\\\Stansilav.Datskovski\\\\Desktop\\\\phi_psi\\\\alignTestCase\>\"", 
    "~~", 
    RowBox[{"ToString", "@", "TN"}], "~~", "\"\<.txt\>\""}], ",", " ", "EX", 
   ",", " ", "\"\<Text\>\""}], "]"}]}], "Input",
 CellChangeTimes->{{3.4602864582374353`*^9, 3.4602864595968103`*^9}, {
  3.4602865489249353`*^9, 3.4602865496280603`*^9}, {3.4602866340968103`*^9, 
  3.4602866567686853`*^9}, {3.4602869046124353`*^9, 3.4602869095811853`*^9}, {
  3.4602872439718103`*^9, 3.4602873130186853`*^9}, {3.4602873626905603`*^9, 
  3.4602874026124353`*^9}, {3.4602874329249353`*^9, 3.4602874367374353`*^9}, {
  3.4602885982843103`*^9, 3.4602885991280603`*^9}, {3.4602887170655603`*^9, 
  3.4602887430499353`*^9}, {3.4602887739093103`*^9, 3.4602887876593103`*^9}, {
  3.4602888528155603`*^9, 3.4602888895030603`*^9}, {3.4602889224093103`*^9, 
  3.4602889522843103`*^9}, {3.4602889873155603`*^9, 3.4602890757999353`*^9}, {
  3.4602891165186853`*^9, 3.4602891591436853`*^9}}],

Cell[BoxData["\<\"C:\\\\Documents and \
Settings\\\\Stansilav.Datskovski\\\\Desktop\\\\phi_psi\\\\alignTestCase10.txt\
\"\>"], "Output",
 CellChangeTimes->{{3.4602890332999353`*^9, 3.4602890430030603`*^9}, 
   3.4602890836749353`*^9, {3.4602891195030603`*^9, 3.4602891597999353`*^9}}]
}, Open  ]]
},
WindowSize->{1912, 1100},
WindowMargins->{{0, Automatic}, {Automatic, 0}},
FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (February 18, 2009)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[545, 20, 336, 8, 31, "Input"],
Cell[CellGroupData[{
Cell[906, 32, 9266, 228, 392, "Input"],
Cell[10175, 262, 284, 4, 30, "Output"]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
